home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / URI / URL.pm < prev   
Encoding:
Perl POD Document  |  1999-12-28  |  24.8 KB  |  914 lines

  1. package URI::URL;
  2.  
  3. $VERSION = "4.11";   # $Date: 1997/06/20 09:25:49 $
  4. sub Version { $VERSION; }
  5.  
  6. require 5.002;
  7.  
  8. require Exporter;
  9. @ISA = qw(Exporter);
  10. @EXPORT = qw(url);
  11.  
  12. require AutoLoader;
  13. *AUTOLOAD = \&AutoLoader::AUTOLOAD;
  14.  
  15. use Carp ();
  16.  
  17.  
  18.  
  19. use strict;
  20. use vars qw($reserved $reserved_no_slash $reserved_no_form $unsafe
  21.         $COMPAT_VER_3
  22.         $Debug $Strict_URL
  23.        );
  24.  
  25. $reserved          = ";\\/?:\\@&=+#%"; # RFC 1738 reserved pluss '#' and '%'
  26. $reserved_no_slash = ";?:\\@&=+#%";    # used when escaping path
  27. $reserved_no_form  = ";\\/?:\\@#%";    # used when escaping params and query
  28.  
  29. $unsafe   = "\x00-\x20{}|\\\\^\\[\\]`<>\"\x7F-\xFF";
  30.  
  31. $Debug         = 0;     # set to 1 to print URLs on creation
  32. $COMPAT_VER_3  = 0;     # should we try to behave in the old way
  33. $Strict_URL    = 0;     # see new()
  34.  
  35. use overload ( '""' => 'as_string', 'fallback' => 1 );
  36.  
  37. my %Implementor = (); # mapping from scheme to implementation class
  38.  
  39.  
  40. sub url ($;$)
  41. {
  42.     URI::URL->new(@_);
  43. }
  44.  
  45.  
  46.  
  47. sub new
  48. {
  49.     my($class, $init, $base) = @_;
  50.  
  51.     my $self;
  52.     if (ref $init) {
  53.     $self = $init->clone;
  54.     $self->base($base) if $base;
  55.     } else {
  56.     $init = "" unless defined $init;
  57.     $init =~ s/\s+//g;
  58.     $init =~ s/^<(?:URL:)?(.*)>$/$1/;
  59.  
  60.     my($scheme) = $init =~ m/^([.+\-\w]+):/;
  61.     if (!$scheme and $base){ # get scheme from base
  62.         if (ref $base){ # may be object or just a string
  63.         $scheme = $base->scheme;
  64.         } else {
  65.         $scheme = $1 if $base =~ m/^([.+\-\w]+):/;
  66.         }
  67.     }
  68.     unless($scheme){
  69.         Carp::croak("Unable to determine scheme for '$init'")
  70.         if $Strict_URL;
  71.         $scheme = 'http';
  72.     }
  73.     my $impclass = URI::URL::implementor($scheme);
  74.     unless ($impclass) {
  75.         Carp::croak("URI::URL scheme '$scheme' is not supported")
  76.         if $Strict_URL;
  77.         require URI::URL::_generic;
  78.         URI::URL::implementor($scheme, 'URI::URL::_generic');
  79.         $impclass = 'URI::URL::_generic';
  80.     }
  81.  
  82.     $self->{'_orig_url'} = $init if $Debug;
  83.     $self = $impclass->new($init, $base);
  84.     }
  85.     $self->print_on('STDERR') if $Debug;
  86.     return $self;
  87. }
  88.  
  89.  
  90. sub clone
  91. {
  92.     my $self = shift;
  93.     bless { %$self }, ref $self;
  94. }
  95.  
  96.  
  97. sub implementor
  98. {
  99.     my($scheme, $impclass) = @_;
  100.     unless (defined $scheme) {
  101.     require URI::URL::_generic;
  102.     return 'URI::URL::_generic';
  103.     }
  104.  
  105.     $scheme = lc($scheme);
  106.     if ($impclass) {
  107.     $impclass->_init_implementor($scheme);
  108.     my $old = $Implementor{$scheme};
  109.     $Implementor{$scheme} = $impclass;
  110.     return $old;
  111.     }
  112.  
  113.     my $ic = $Implementor{$scheme};
  114.     return $ic if $ic;
  115.  
  116.     $ic = "URI::URL::$scheme";  # default location
  117.     no strict 'refs';
  118.     unless (defined @{"${ic}::ISA"}) {
  119.     eval { require "URI/URL/$scheme.pm"; };
  120.     die $@ if $@ && $@ !~ /Can\'t locate/;
  121.     $ic = '' unless defined @{"${ic}::ISA"};
  122.     }
  123.     if ($ic) {
  124.     $ic->_init_implementor($scheme);
  125.     $Implementor{$scheme} = $ic;
  126.     }
  127.     $ic;
  128. }
  129.  
  130.  
  131. sub _init_implementor
  132. {
  133.     my($class, $scheme) = @_;
  134.  
  135.     if ($] < 5.003_17) {
  136.     no strict qw(refs);
  137.     %{"${class}::OVERLOAD"} = %URI::URL::OVERLOAD
  138.         unless defined %{"${class}::OVERLOAD"};
  139.     }
  140. }
  141.  
  142.  
  143.  
  144. sub _elem
  145. {
  146.     my($self, $element, @val) = @_;
  147.     my $old = $self->{$element};
  148.     return $old unless @val;
  149.     $self->{$element} = $val[0]; # general case
  150.     $self->{'_str'} = '';        # void cached string
  151.     $old;
  152. }
  153.  
  154.  
  155.  
  156. sub bad_method;
  157.  
  158. *netloc       = \&bad_method;
  159. *user         = \&bad_method;
  160. *password     = \&bad_method;
  161. *host         = \&bad_method;
  162. *port         = \&bad_method;
  163. *default_port = \&bad_method;
  164.  
  165. *full_path    = \&bad_method;
  166. *epath        = \&bad_method;
  167. *eparams      = \&bad_method;
  168. *equery       = \&bad_method;
  169.  
  170. *path         = \&bad_method;
  171. *path_components = \&bad_method;
  172. *params       = \&bad_method;
  173. *query        = \&bad_method;
  174. *frag         = \&bad_method;
  175.  
  176.  
  177. sub newlocal;
  178. sub strict;
  179. sub base;
  180. sub scheme;
  181. sub crack;
  182. sub abs;
  183. sub rel;
  184. sub as_string;
  185. sub eq;
  186. sub print_on;
  187. sub unsafe;
  188. sub escape;
  189. sub unescape;
  190.  
  191. sub DESTROY { }
  192.  
  193. 1;
  194. __END__
  195.  
  196. sub newlocal
  197. {
  198.     require URI::URL::file;
  199.     my($class, $path) = @_;
  200.     newlocal URI::URL::file $path;  # pass it on the the file class
  201. }
  202.  
  203. sub strict
  204. {
  205.     return $Strict_URL unless @_;
  206.     my $old = $Strict_URL;
  207.     $Strict_URL = $_[0];
  208.     $old;
  209. }
  210.  
  211. sub base {
  212.     my $self = shift;
  213.     return $self->_elem('_base', @_) if @_;      # set
  214.  
  215.     my $base = $self->_elem('_base');            # get
  216.     return undef unless defined $base;
  217.     unless (ref $base){
  218.     $base = new URI::URL $base;
  219.     $self->_elem('_base', $base); # set new object
  220.     }
  221.     $base;
  222. }
  223.  
  224. sub scheme {
  225.     my $self = shift;
  226.     my $old = $self->{'scheme'};
  227.     return $old unless @_;
  228.  
  229.     my $newscheme = shift;
  230.     if (defined($newscheme) && length($newscheme)) {
  231.     my $str = $self->as_string;
  232.     $str =~ s/^[\w+\-.]+://;
  233.     my $newself = new URI::URL "$newscheme:$str";
  234.     %$self = %$newself;
  235.     bless $self, ref($newself);
  236.     } else {
  237.     $self->{'scheme'} = undef;
  238.     }
  239.     $old;
  240. }
  241.  
  242. sub crack
  243. {
  244.     my $self = shift;
  245.     ($self->scheme,  # 0: scheme
  246.      undef,          # 1: user
  247.      undef,          # 2: passwd
  248.      undef,          # 3: host
  249.      undef,          # 4: port
  250.      undef,          # 5: path
  251.      undef,          # 6: params
  252.      undef,          # 7: query
  253.      undef           # 8: fragment
  254.     )
  255. }
  256.  
  257. sub abs { shift->clone; }
  258. sub rel { shift->clone; }
  259.  
  260. sub as_string {
  261.     "";
  262. }
  263.  
  264. sub eq {
  265.     my($self, $other) = @_;
  266.     $other = URI::URL->new($other, $self) unless ref $other;
  267.     ref($self) eq ref($other) &&
  268.       $self->scheme eq $other->scheme &&
  269.       $self->as_string eq $other->as_string;  # Case-sensitive
  270. }
  271.  
  272. sub bad_method {
  273.     my $self = shift;
  274.     my $scheme = $self->scheme;
  275.     Carp::croak("Illegal method called for $scheme: URL")
  276.     if $Strict_URL;
  277.     undef;
  278. }
  279.  
  280. sub print_on
  281. {
  282.     no strict qw(refs);  # because we use strings as filehandles
  283.     my $self = shift;
  284.     my $fh = shift || 'STDOUT';
  285.     my($k, $v);
  286.     print $fh "Dump of URL $self...\n";
  287.     foreach $k (sort keys %$self){
  288.     $v = $self->{$k};
  289.     $v = 'UNDEF' unless defined $v;
  290.     print $fh "  $k\t'$v'\n";
  291.     }
  292. }
  293.  
  294.  
  295. sub unsafe {
  296.     Carp::croak("The unsafe() method not supported by URI::URL any more!
  297. If you need this feature badly, then you should make a subclass of
  298. the URL-schemes you need to modify the behavior for.  The method
  299. was called");
  300. }
  301.  
  302. sub escape {
  303.     Carp::croak("The escape() method not supported by URI::URL any more!
  304. Use the URI::Escape module instead.  The method was called");
  305. }
  306.  
  307. sub unescape {
  308.     Carp::croak("unescape() method not supported by URI::URL any more!
  309. Use the URI::Escape module instead.  The method was called");
  310. }
  311.  
  312. 1;
  313.  
  314.  
  315.  
  316. =head1 NAME
  317.  
  318. URI::URL - Uniform Resource Locators (absolute and relative)
  319.  
  320. =head1 SYNOPSIS
  321.  
  322.  use URI::URL;
  323.  
  324.  $url1 = new URI::URL 'http://www.perl.com/%7Euser/gisle.gif';
  325.  $url2 = new URI::URL 'gisle.gif', 'http://www.com/%7Euser';
  326.  $url3 = url 'http://www.sn.no/'; # handy constructor
  327.  $url4 = $url2->abs;       # get absolute url using base
  328.  $url5 = $url2->abs('http:/other/path');
  329.  $url6 = newlocal URI::URL 'test';
  330.  
  331.  $str1 = $url->as_string;  # complete escaped URL string
  332.  $str2 = $url->full_path;  # escaped path+params+query
  333.  $str3 = "$url";           # use operator overloading
  334.  
  335.  $scheme   = $url->scheme;
  336.  $netloc   = $url->netloc; # see user,password,host,port below
  337.  $path     = $url->path;
  338.  $params   = $url->params;
  339.  $query    = $url->query;
  340.  $frag     = $url->frag;
  341.  
  342.  $path     = $url->epath;
  343.  $params   = $url->eparams;
  344.  $query    = $url->equery;
  345.  
  346.  $user     = $url->user;
  347.  $password = $url->password;
  348.  $host     = $url->host;
  349.  $port     = $url->port;   # returns default if not defined
  350.  
  351.  @path     = $url->path_components;
  352.  
  353.  @keywords = $url->keywords;
  354.  @form     = $url->query_form;
  355.  
  356.  $url->scheme('http');
  357.  $url->host('www.w3.org');
  358.  $url->port($url->default_port);
  359.  $url->base($url5);                      # use string or object
  360.  $url->keywords(qw(dog bones));
  361.  
  362.  $url = new URI::URL "file:/foo/bar";
  363.  open(F, $url->local_path) or die;
  364.  
  365.  if ($url->eq("http://www.sn.no")) or die;
  366.  
  367. =head1 DESCRIPTION
  368.  
  369. This module implements the URI::URL class representing Uniform
  370. Resource Locators (URL). URLs provide a compact string representation
  371. for resources available via the Internet. Both absolute (RFC 1738) and
  372. relative (RFC 1808) URLs are supported.
  373.  
  374. URI::URL objects are created by calling new(), which takes as argument
  375. a string representation of the URL or an existing URL object reference
  376. to be cloned. Specific individual elements can then be accessed via
  377. the scheme(), user(), password(), host(), port(), path(), params(),
  378. query() and frag() methods.  In addition escaped versions of the path,
  379. params and query can be accessed with the epath(), eparams() and
  380. equery() methods.  Note that some URL schemes will support all these
  381. methods.
  382.  
  383. The object constructor new() must be able to determine the scheme for
  384. the URL.  If a scheme is not specified in the URL itself, it will use
  385. the scheme specified by the base URL. If no base URL scheme is defined
  386. then new() will croak if URI::URL::strict(1) has been invoked,
  387. otherwise I<http> is silently assumed.  Once the scheme has been
  388. determined new() then uses the implementor() function to determine
  389. which class implements that scheme.  If no implementor class is
  390. defined for the scheme then new() will croak if URI::URL::strict(1)
  391. has been invoked, otherwise the internal generic URL class is assumed.
  392.  
  393. Internally defined schemes are implemented by the
  394. URI::URL::I<scheme_name> module.  The URI::URL::implementor() function
  395. can be used to explicitly set the class used to implement a scheme if
  396. you want to override this.
  397.  
  398.  
  399. =head1 HOW AND WHEN TO ESCAPE
  400.  
  401.  
  402. =over 3
  403.  
  404. =item This is an edited extract from a URI specification:
  405.  
  406. The printability requirement has been met by specifying a safe set of
  407. characters, and a general escaping scheme for encoding "unsafe"
  408. characters. This "safe" set is suitable, for example, for use in
  409. electronic mail.  This is the canonical form of a URI.
  410.  
  411. There is a conflict between the need to be able to represent many
  412. characters including spaces within a URI directly, and the need to be
  413. able to use a URI in environments which have limited character sets
  414. or in which certain characters are prone to corruption. This conflict
  415. has been resolved by use of an hexadecimal escaping method which may
  416. be applied to any characters forbidden in a given context. When URLs
  417. are moved between contexts, the set of characters escaped may be
  418. enlarged or reduced unambiguously.  The canonical form for URIs has
  419. all white spaces encoded.
  420.  
  421. =item Notes:
  422.  
  423. A URL string I<must>, by definition, consist of escaped
  424. components. Complete URLs are always escaped.
  425.  
  426. The components of a URL string must be I<individually> escaped.  Each
  427. component of a URL may have a separate requirements regarding what
  428. must be escaped, and those requirements are also dependent on the URL
  429. scheme.
  430.  
  431. Never escape an already escaped component string.
  432.  
  433. =back
  434.  
  435. This implementation expects an escaped URL string to be passed to
  436. new() and will return a fully escaped URL string from as_string()
  437. and full_path().
  438.  
  439. Individual components can be manipulated in unescaped or escaped
  440. form. The following methods return/accept unescaped strings:
  441.  
  442.     scheme                  path
  443.     user                    params
  444.     password                query
  445.     host                    frag
  446.     port
  447.  
  448. The following methods return/accept partial I<escaped> strings:
  449.  
  450.     netloc                  eparams
  451.     epath                   equery
  452.  
  453. I<Partial escaped> means that only reserved characters
  454. (i.e. ':', '@', '/', ';', '?', '=', '&' in addition to '%', '.' and '#')
  455. needs to be escaped when they are to be treated as normal characters.
  456. I<Fully escaped> means that all unsafe characters are escaped. Unsafe
  457. characters are all all control characters (%00-%1F and %7F), all 8-bit
  458. characters (%80-%FF) as well
  459. as '{', '}', '|', '\', '^', '[', ']' '`', '"', '<' and '>'.
  460. Note that the character '~' is B<not> considered
  461. unsafe by this library as it is common practice to use it to reference
  462. personal home pages, but it is still unsafe according to RFC 1738.
  463.  
  464. =head1 ADDING NEW URL SCHEMES
  465.  
  466. New URL schemes or alternative implementations for existing schemes
  467. can be added to your own code. To create a new scheme class use code
  468. like:
  469.  
  470.    package MYURL::foo;
  471.    @ISA = (URI::URL::implementor());   # inherit from generic scheme
  472.  
  473. The 'URI::URL::implementor()' function call with no parameters returns
  474. the name of the class which implements the generic URL scheme
  475. behaviour (typically C<URI::URL::_generic>). All hierarchical schemes
  476. should be derived from this class.
  477.  
  478. Your class can then define overriding methods (e.g., new(), _parse()
  479. as required).
  480.  
  481. To register your new class as the implementor for a specific scheme
  482. use code like:
  483.  
  484.    URI::URL::implementor('x-foo', 'MYURL::foo');
  485.  
  486. Any new URL created for scheme 'x-foo' will be implemented by your
  487. C<MYURL::foo> class. Existing URLs will not be affected.
  488.  
  489.  
  490. =head1 FUNCTIONS
  491.  
  492. =over 3
  493.  
  494. =item new URI::URL $url_string [, $base_url]
  495.  
  496. This is the object constructor.  It will create a new URI::URL object,
  497. initialized from the URL string.  To trap bad or unknown URL schemes
  498. use:
  499.  
  500.  $obj = eval { new URI::URL "snews:comp.lang.perl.misc" };
  501.  
  502. or set URI::URL::strict(0) if you do not care about bad or unknown
  503. schemes.
  504.  
  505. =item newlocal URI::URL $path;
  506.  
  507. Returns an URL object that denotes a path within the local filesystem.
  508. Paths not starting with '/' are interpreted relative to the current
  509. working directory.  This constructor always return an absolute 'file'
  510. URL.
  511.  
  512. =item url($url_string, [, $base_url])
  513.  
  514. Alternative constructor function.  The url() function is exported by
  515. the URI::URL module and is easier both to type and read than calling
  516. URI::URL->new directly.  Useful for constructs like this:
  517.  
  518.    $h = url($str)->host;
  519.  
  520. This function is just a wrapper for URI::URL->new.
  521.  
  522. =item URI::URL::strict($bool)
  523.  
  524. If strict is true then we croak on errors.  The function returns the
  525. previous value.
  526.  
  527. =item URI::URL::implementor([$scheme, [$class]])
  528.  
  529. Use this function to get or set implementor class for a scheme.
  530. Returns '' if specified scheme is not supported.  Returns generic URL
  531. class if no scheme specified.
  532.  
  533. =back
  534.  
  535. =head1 METHODS
  536.  
  537. This section describes the methods available for an URI::URL object.
  538. Note that some URL schemes will disallow some of these methods and
  539. will croak if they are used.  Some URL schemes add additional methods
  540. that are described in the sections to follow.
  541.  
  542. Attribute access methods marked with (*) can take an optional argument
  543. to set the value of the attribute, and they always return the old
  544. value.
  545.  
  546. =over 3
  547.  
  548. =item $url->abs([$base, [$allow_scheme_in_relative_urls]])
  549.  
  550. The abs() method attempts to return a new absolute URI::URL object
  551. for a given URL.  In order to convert a relative URL into an absolute
  552. one, a I<base> URL is required. You can associate a default base with a
  553. URL either by passing a I<base> to the new() constructor when a
  554. URI::URL is created or using the base() method on the object later.
  555. Alternatively you can specify a one-off base as a parameter to the
  556. abs() method.
  557.  
  558. Some older parsers used to allow the scheme name to be present in the
  559. relative URL if it was the same as the base URL scheme.  RFC1808 says
  560. that this should be avoided, but you can enable this old behaviour by
  561. passing a TRUE value as the second argument to the abs() method.  The
  562. difference is demonstrated by the following examples:
  563.  
  564.   url("http:foo")->abs("http://host/a/b")     ==>  "http:foo"
  565.   url("http:foo")->abs("http://host/a/b", 1)  ==>  "http:/host/a/foo"
  566.  
  567. The rel() method will do the opposite transformation.
  568.  
  569. =item $url->as_string
  570.  
  571. Returns a string representing the URL in its canonical form.  All
  572. unsafe characters will be escaped.  This method is overloaded as the
  573. perl "stringify" operator, which means that URLs can be used as
  574. strings in many contexts.
  575.  
  576. =item $url->base (*)
  577.  
  578. Get/set the base URL associated with the current URI::URL object.  The
  579. base URL matters when you call the abs() method.
  580.  
  581. =item $url->clone
  582.  
  583. Returns a copy of the current URI::URL object.
  584.  
  585. =item $url->crack
  586.  
  587. Return a 9 element array with the following content:
  588.  
  589.    0: $url->scheme *)
  590.    1: $url->user
  591.    2: $url->password
  592.    3: $url->host
  593.    4: $url->port
  594.    5: $url->epath
  595.    6: $url->eparams
  596.    7: $url->equery
  597.    8: $url->frag
  598.  
  599. All elements except I<scheme> will be undefined if the corresponding
  600. URL part is not available.
  601.  
  602. B<Note:> The scheme (first element) returned by crack will aways be
  603. defined.  This is different from what the $url->scheme returns, since
  604. it will return I<undef> for relative URLs.
  605.  
  606. =item $url->default_port
  607.  
  608. Returns the default port number for the URL scheme that the URI::URL
  609. belongs too.
  610.  
  611. =item $url->eparams (*)
  612.  
  613. Get/set the URL parameters in escaped form.
  614.  
  615. =item $url->epath (*)
  616.  
  617. Get/set the URL path in escaped form.
  618.  
  619. =item $url->eq($other_url)
  620.  
  621. Compare two URLs to decide if they match or not.  The rules for how
  622. comparison is made varies for different parts of the URLs; scheme and
  623. netloc comparison is case-insensitive, and escaped chars match their
  624. %XX encoding unless they are "reserved" or "unsafe".
  625.  
  626. =item $url->equery (*)
  627.  
  628. Get/set the URL query string in escaped form.
  629.  
  630. =item $url->full_path
  631.  
  632. Returns the string "/path;params?query".  This is the string that is
  633. passed to a remote server in order to access the document.
  634.  
  635. =item $url->frag (*)
  636.  
  637. Get/set the fragment (unescaped)
  638.  
  639. =item $url->host (*)
  640.  
  641. Get/set the host (unescaped)
  642.  
  643. =item $url->netloc (*)
  644.  
  645. Get/set the network location in escaped form.  Setting the network
  646. location will affect 'user', 'password', 'host' and 'port'.
  647.  
  648. =item $url->params (*)
  649.  
  650. Get/set the URL parameters (unescaped)
  651.  
  652. =item $url->password (*)
  653.  
  654. Get/set the password (unescaped)
  655.  
  656. =item $url->path (*)
  657.  
  658. Get/set the path (unescaped).  This method will croak if any of the
  659. path components in the return value contain the "/" character.  You
  660. should use the epath() method to be safe.
  661.  
  662. =item $url->path_components (*)
  663.  
  664. Get/set the path using a list of unescaped path components.  The
  665. return value will loose the distinction beween '.' and '%2E'.  When
  666. setting a value, a '.' is converted to be a literal '.' and is
  667. therefore encoded as '%2E'.
  668.  
  669. =item $url->port (*)
  670.  
  671. Get/set the network port (unescaped)
  672.  
  673. =item $url->rel([$base])
  674.  
  675. Return a relative URL if possible.  This is the opposite of what the
  676. abs() method does.  For instance:
  677.  
  678.    url("http://www.math.uio.no/doc/mail/top.html",
  679.        "http://www.math.uio.no/doc/linux/")->rel
  680.  
  681. will return a relative URL with path set to "../mail/top.html" and
  682. with the same base as the original URL.
  683.  
  684. If the original URL already is relative or the scheme or netloc does
  685. not match the base, then a copy of the original URL is returned.
  686.  
  687.  
  688. =item $url->print_on(*FILEHANDLE);
  689.  
  690. Prints a verbose presentation of the contents of the URL object to
  691. the specified file handle (default STDOUT).  Mainly useful for
  692. debugging.
  693.  
  694. =item $url->scheme (*)
  695.  
  696. Get/set the scheme for the URL.
  697.  
  698. =item $url->query (*)
  699.  
  700. Get/set the query string (unescaped).  This method will croak if the
  701. string returned contains both '+' and '%2B' or '=' together with '%3D'
  702. or '%26'.  You should use the equery() method to be safe.
  703.  
  704. =item $url->user (*)
  705.  
  706. Get/set the URL user name (unescaped)
  707.  
  708. =back
  709.  
  710. =head1 HTTP METHODS
  711.  
  712. For I<http> URLs you may also access the query string using the
  713. keywords() and the query_form() methods.  Both will croak if the query
  714. is not of the correct format.  The encodings look like this:
  715.  
  716.   word1+word2+word3..        # keywords
  717.   key1=val1&key2=val2...     # query_form
  718.  
  719. Note: These functions does not return the old value when they are used
  720. to set a value of the query string.
  721.  
  722. =over 3
  723.  
  724. =item $url->keywords (*)
  725.  
  726. The keywords() method returns a list of unescaped strings.  The method
  727. can also be used to set the query string by passing in the keywords as
  728. individual arguments to the method.
  729.  
  730. =item $url->query_form (*)
  731.  
  732. The query_form() method return a list of unescaped key/value pairs.
  733. If you assign the return value to a hash you might loose some values
  734. if the key is repeated (which it is allowed to do).
  735.  
  736. This method can also be used to set the query sting of the URL like this:
  737.  
  738.   $url->query_form(foo => 'bar', foo => 'baz', equal => '=');
  739.  
  740. If the value part of a key/value pair is a reference to an array, then
  741. it will be converted to separate key/value pairs for each value.  This
  742. means that these two calls are equal:
  743.  
  744.   $url->query_form(foo => 'bar', foo => 'baz');
  745.   $url->query_form(foo => ['bar', 'baz']);
  746.  
  747. =back
  748.  
  749. =head1 FILE METHODS
  750.  
  751. The I<file> URLs implement the local_path() method that returns a path
  752. suitable for access to files within the current filesystem.  These
  753. methods can B<not> be used to set the path of the URL.
  754.  
  755. =over 3
  756.  
  757. =item $url->local_path
  758.  
  759. This method is really just an alias for one of the methods below
  760. depending on what system you run on.
  761.  
  762. =item $url->unix_path
  763.  
  764. Returns a path suitable for use on a Unix system.  This method will
  765. croak if any of the path segments contains a "/" or a NULL character.
  766.  
  767. =item $url->dos_path
  768.  
  769. Returns a path suitable for use on a MS-DOS or MS-Windows system.
  770.  
  771. =item $url->mac_path
  772.  
  773. Returns a path suitable for use on a Macintosh system.
  774.  
  775. =item $url->vms_path
  776.  
  777. Returns a path suitable for use on a VMS system.  VMS is a trademark
  778. of Digital.
  779.  
  780. =back
  781.  
  782. =head1 GOPHER METHODS
  783.  
  784. The methods access the parts that are specific for the gopher URLs.
  785. These methods access different parts of the $url->path.
  786.  
  787. =over 3
  788.  
  789. =item $url->gtype (*)
  790.  
  791. =item $url->selector (*)
  792.  
  793. =item $url->search (*)
  794.  
  795. =item $url->string (*)
  796.  
  797. =back
  798.  
  799. =head1 NEWS METHODS
  800.  
  801. =over 3
  802.  
  803. =item $url->group (*)
  804.  
  805. =item $url->article (*)
  806.  
  807. =back
  808.  
  809. =head1 WAIS METHODS
  810.  
  811. The methods access the parts that are specific for the wais URLs.
  812. These methods access different parts of the $url->path.
  813.  
  814. =over 3
  815.  
  816. =item $url->database (*)
  817.  
  818. =item $url->wtype (*)
  819.  
  820. =item $url->wpath (*)
  821.  
  822. =back
  823.  
  824. =head1 MAILTO METHODS
  825.  
  826. =over 3
  827.  
  828. =item $url->address (*)
  829.  
  830. The mail address can also be accessed with the netloc() method.
  831.  
  832. =back
  833.  
  834.  
  835. =head1 WHAT A URL IS NOT
  836.  
  837. URL objects do not, and should not, know how to 'get' or 'put' the
  838. resources they specify locations for, anymore than a postal address
  839. 'knows' anything about the postal system. The actual access/transfer
  840. should be achieved by some form of transport agent class (see
  841. L<LWP::UserAgent>). The agent class can use the URL class, but should
  842. not be a subclass of it.
  843.  
  844. =head1 COMPATIBILITY
  845.  
  846. This is a listing incompatibilities with URI::URL version 3.x:
  847.  
  848. =over 3
  849.  
  850. =item unsafe(), escape() and unescape()
  851.  
  852. These methods not supported any more.
  853.  
  854. =item full_path() and as_string()
  855.  
  856. These methods does no longer take a second argument which specify the
  857. set of characters to consider as unsafe.
  858.  
  859. =item '+' in the query-string
  860.  
  861. The '+' character in the query part of the URL was earlier considered
  862. to be an encoding of a space. This was just bad influence from Mosaic.
  863. Space is now encoded as '%20'.
  864.  
  865. =item path() and query()
  866.  
  867. This methods will croak if they loose information.  Use epath() or
  868. equery() instead.  The path() method will for instance loose
  869. information if any path segment contain an (encoded) '/' character.
  870.  
  871. The path() now consider a leading '/' to be part of the path.  If the
  872. path is empty it will default to '/'.  You can get the old behaviour
  873. by setting $URI::URL::COMPAT_VER_3 to TRUE before accessing the path()
  874. method.
  875.  
  876. =item netloc()
  877.  
  878. The string passed to netloc is now assumed to be escaped.  The string
  879. returned will also be (partially) escaped.
  880.  
  881. =item sub-classing
  882.  
  883. The path, params and query is now stored internally in unescaped form.
  884. This might affect sub-classes of the URL scheme classes.
  885.  
  886. =back
  887.  
  888. =head1 AUTHORS / ACKNOWLEDGMENTS
  889.  
  890. This module is (distantly) based on the C<wwwurl.pl> code in the
  891. libwww-perl distribution developed by Roy Fielding
  892. <fielding@ics.uci.edu>, as part of the Arcadia project at the
  893. University of California, Irvine, with contributions from Brooks
  894. Cutter.
  895.  
  896. Gisle Aas <aas@sn.no>, Tim Bunce <Tim.Bunce@ig.co.uk>, Roy Fielding
  897. <fielding@ics.uci.edu> and Martijn Koster <m.koster@webcrawler.com>
  898. (in English alphabetical order) have collaborated on the complete
  899. rewrite for Perl 5, with input from other people on the libwww-perl
  900. mailing list.
  901.  
  902. If you have any suggestions, bug reports, fixes, or enhancements, send
  903. them to the libwww-perl mailing list at <libwww-perl@ics.uci.edu>.
  904.  
  905. =head1 COPYRIGHT
  906.  
  907. Copyright 1995-1996 Gisle Aas.
  908. Copyright 1995 Martijn Koster.
  909.  
  910. This program is free software; you can redistribute it and/or modify
  911. it under the same terms as Perl itself.
  912.  
  913. =cut
  914.